package handler

import (
	"github.com/name5566/leaf/gate"
	"server/game/house"
	"server/msg/jsonData"
)

func HouseList(args []interface{}) {
	m := args[0].(*jsonData.MsgHouseListReq)
	// 消息的发送者
	a := args[1].(gate.Agent)
	info, err := house.HouseList(m.UserId)
	if err != nil {
		a.WriteMsg(&jsonData.MsgRes{
			Ret:     1,
			Message: err.Error(),
		})
		return
	}
	a.WriteMsg(&jsonData.MsgRes{
		Ret:       0,
		Result:    info,
		RequestId: m.RequestId,
	})
}
func UnLockHouse(args []interface{}) {
	m := args[0].(*jsonData.MsgUnLockHouseReq)
	// 消息的发送者
	a := args[1].(gate.Agent)
	info, err := house.UnLockHouse(m.UserId, m.HouseId)
	if err != nil {
		a.WriteMsg(&jsonData.MsgRes{
			Ret:       1,
			Message:   err.Error(),
			RequestId: m.RequestId,
		})
		return
	}
	a.WriteMsg(&jsonData.MsgRes{
		Ret:       0,
		Result:    info,
		RequestId: m.RequestId,
	})
}
func UnlockFurniture(args []interface{}) {
	m := args[0].(*jsonData.MsgUnlockFurnitureReq)
	// 消息的发送者
	a := args[1].(gate.Agent)
	info, err := house.UnlockFurniture(m.UserId, m.HouseId, m.FurnitureId)
	if err != nil {
		a.WriteMsg(&jsonData.MsgRes{
			Ret:       1,
			Message:   err.Error(),
			RequestId: m.RequestId,
		})
		return
	}
	a.WriteMsg(&jsonData.MsgRes{
		Ret:       0,
		Result:    info,
		RequestId: m.RequestId,
	})
}
func AddFurniture(args []interface{}) {
	m := args[0].(*jsonData.MsgAddFurnitureReq)
	// 消息的发送者
	a := args[1].(gate.Agent)
	info, err := house.AddFurniture(m.UserId, m.HouseId, m.FurnitureId)
	if err != nil {
		a.WriteMsg(&jsonData.MsgRes{
			Ret:       1,
			Message:   err.Error(),
			RequestId: m.RequestId,
		})
		return
	}
	a.WriteMsg(&jsonData.MsgRes{
		Ret:       0,
		Result:    info,
		RequestId: m.RequestId,
	})
}
func NewHouse(args []interface{}) {
	m := args[0].(*jsonData.MsgNewHouseReq)
	// 消息的发送者
	a := args[1].(gate.Agent)
	info, err := house.NewUserHouse(m.UserId, m.HouseId)
	if err != nil {
		a.WriteMsg(&jsonData.MsgRes{
			Ret:       1,
			Message:   err.Error(),
			RequestId: m.RequestId,
		})
		return
	}
	a.WriteMsg(&jsonData.MsgRes{
		Ret:       0,
		Result:    info,
		RequestId: m.RequestId,
	})
}
